
package com.example.generator.config;

import java.time.LocalTime;
import java.util.Collections;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import io.swagger.annotations.ApiOperation;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.builders.RequestParameterBuilder;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


/**
 * Swagger2的接口配置
 *
 * @author ruoyi
 */

@Configuration
@EnableSwagger2
public class SwaggerConfig
{
    @Bean
    public Docket createRestApi(RuoYiConfig ruoYiConfig) {
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                // 用来创建该API的基本信息，展示在文档的页面中（自定义展示的信息）
                .apiInfo(new ApiInfoBuilder()
                        .title(ruoYiConfig.getName() + "接口文档")
                        .description(ruoYiConfig.getName() + " 接口文档")
                        // 作者信息
                        .contact(new Contact("LZY", null, null))
                        .version("版本号: " + ruoYiConfig.getVersion())
                        .build()
                )
                //LocalTime显示问题
                .directModelSubstitute(LocalTime.class,String.class)
                // 设置哪些接口暴露给Swagger展示
                .select()
                // 扫描所有有注解的api，用这种方式更灵活
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                // 扫描所有 .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build();

        docket.globalRequestParameters(Collections.singletonList(
                new RequestParameterBuilder()
                        .name("Authorization")
                        .description("令牌")
                        .required(true)
                        .in("header")
                        .build()
        ));
        docket.useDefaultResponseMessages(false);

        return docket;
    }
}

